Skip to content

Do not use root logger#2082

Open
lachesis wants to merge 2 commits into
mindee:mainfrom
lachesis:lachesis/no-root-logger
Open

Do not use root logger#2082
lachesis wants to merge 2 commits into
mindee:mainfrom
lachesis:lachesis/no-root-logger

Conversation

@lachesis

Copy link
Copy Markdown
Contributor

Calling logging.info() at module level with no logger configured triggers logging.basicConfig() automatically (Python's "last resort" behavior) — which creates a StreamHandler on root with WARNING level.

This poisons logging config for anything downstream of this.

Instead, create a logger scoped to doctr package.

Example repro script:

#!/usr/bin/env python
from doctr.io import Document

import logging
logging.basicConfig(level=logging.INFO)

logging.info("I do not see this")
logging.warning("I still see this")

Output:

WARNING:root:I still see this

Expected:

INFO:root:I do not see this
WARNING:root:I still see this

Replaces #2076

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.96%. Comparing base (9c1c6e3) to head (5923734).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2082      +/-   ##
==========================================
+ Coverage   96.94%   96.96%   +0.01%     
==========================================
  Files         156      156              
  Lines        7535     7535              
==========================================
+ Hits         7305     7306       +1     
+ Misses        230      229       -1     
Flag Coverage Δ
unittests 96.96% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lachesis

lachesis commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

I'm happy to rebase this forward if anyone is interested in taking the changes...

@felixdittrich92 felixdittrich92 added this to the 1.1.0 milestone Jul 8, 2026
@felixdittrich92 felixdittrich92 self-assigned this Jul 8, 2026
@felixdittrich92 felixdittrich92 added type: enhancement Improvement module: utils Related to doctr.utils module: models Related to doctr.models ext: tests Related to tests folder labels Jul 8, 2026

@felixdittrich92 felixdittrich92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lachesis 👋

Thanks for the PR yes please rebase your PR.

And one thing please use the logger init at module level

For example:

import logging
import xyz


logger = logging.getLogger(__name__)
...code
logger.warning("No model URL or Path provided, using default initialization.")
...code
logger.info("XYZ")

Please verify that each module which uses logging. init it's logger on top of the module like in the example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext: tests Related to tests folder module: models Related to doctr.models module: utils Related to doctr.utils type: enhancement Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants